<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                collapsible: true,
                fit: true,
                striped: true,
                pagination: true,
                url: "${contextPath}/security/hdw/battery_report_log/page.htm?flagBatteryId=" + ${(flagBatteryId)!''},
                fitColumns: true,
                pageSize: 10,
                pageList: [10, 50, 100],
                idField: 'batteryId',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                frozenColumns: [[
                    {
                        title: '电池ID',
                        align: 'center',
                        field: 'batteryId'
                    }]],
                columns: [
                    [
                        {
                            title: '车牌',
                            align: 'center',
                            field: 'bicycleNo'
                        },
                        {
                            title: 'soc电量',
                            align: 'center',
                            field: 'batteryVolume',
                            formatter: function (val, row) {
                                if (val == null) {
                                    return '';
                                }
                                return val + '%';
                            }
                        },
                        {
                            title: '电量',
                            align: 'center',
                            field: 'dumpEnergy',
                            formatter: function (val, row) {
                                <#--toFixed(2) ：保留2位小数-->
                                return (val / 100).toFixed(2) + "A";
                            }
                        },
                        {
                            title: '信号',
                            align: 'center',
                            field: 'currentSignal'
                        },
                        {
                            title: '信号类型',
                            align: 'center',
                            field: 'networkTypeName'
                        },
                        {
                            title: '经纬类型',
                            align: 'center',
                            field: 'coordinateType'
                        },
                        {
                            title: '经纬度',
                            align: 'center',
                            field: 'lng',
                            formatter: function (val, row) {
                                if (val == null) {
                                    return '';
                                }
                                return (row.lng).toFixed(6) + '/' + (row.lat).toFixed(6);
                            }
                        },
                        {
                            title: '速度',
                            align: 'center',
                            field: 'speed',
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                return (val).toFixed(2)+ 'km/h';
                            }
                        },
                        {
                            title: '电压',
                            align: 'center',
                            field: 'voltage',
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                return (val/100).toFixed(2) + 'V';
                            }
                        },
                        {
                            title: '电流',
                            align: 'center',
                            field: 'electricCurrent',
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                return (val /100).toFixed(2) + 'A';
                            }
                        },
                        {
                            title: '上传频率',
                            align: 'center',
                            field: 'reportInterval',
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                return val + 's';
                            }
                        },
                        {
                            title: '间隔骑行里程',
                            align: 'center',
                            field: 'distance',
                            formatter: function (val) {
                                if (val == null) {
                                    return '';
                                }
                                return val + 'm';
                            }
                        },
                        {
                            title: '间隔消耗电量',
                            align: 'center',
                            field: 'electricity',
                            formatter: function (val, row) {
                                return (val / 100).toFixed(2) + "A";
                            }
                        },
                        {
                            title: '保护状态',
                            align: 'center',
                            field: 'protectionStatusName'
                        },
                        {
                            title: '电池温度℃',
                            align: 'center',
                            field: 'ntcTemperature'
                        },
                        {
                            title: '电池状态',
                            align: 'center',
                            field: 'fetStatusName'
                        },
                        {
                            title: '上传时间',
                            align: 'center',
                            field: 'createTime'
                        }
                    ]
                ],
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            });
        });

        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
        }



        function selectQuery() {
            var batteryId = $('#battery_id').val();
            $("#battery_tree").tree({
                url: '${contextPath}/security/hdw/battery_report_date/tree.htm?batteryId=' + batteryId,
                onLoadSuccess: function (data) {
                    eval(data)
                }

            });
            var datagrid = $('#page_table');

            datagrid.datagrid('options').queryParams = {
                batteryId: batteryId
            };
            datagrid.datagrid('load');
        }

    </script>
    </@app.head>

    <@app.body>

        <@app.container>
            <@app.banner/>

        <div class="main">
            <@app.menu/>

            <div class="content">
                <div class="panel ztree_wrap">
                    <div class="ztree">
                        <div class="ztree_head">
                            <h3>上报日期</h3>
                        </div>
                        <div class="ztree_body easyui-tree" id="battery_tree"
                             data-options="
                                onBeforeSelect: App.tree.toggleSelect,
                                onClick: function(node) {
                                    tree_query();
                                }
                            ">
                        </div>
                    </div>
                </div>
                <div class="panel search" style="margin-left:250px;">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="right" style="color: red">请选择电池编号：</td>
                            <td>
                                <input type="text" class="text" id="battery_id" value="${(batteryId)!}" onclick="selectBattery()"/>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap" style="margin-left:250px;">
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
         <script>
             function tree_query() {
                 var tree = $('#battery_tree');
                 var reportTime = tree.tree('getSelected');
                 if (reportTime) {
                     reportTime = reportTime.id || '';
                 } else {
                     reportTime = '';
                 }
                 if (reportTime.length >= 10) {
                     var datagrid = $('#page_table');
                     var batteryId = $('#battery_id').val();
                     console.log(batteryId);
                     console.log(reportTime);
                     if (batteryId != null) {
                         datagrid.datagrid('options').queryParams = {
                             batteryId: batteryId,
                             createTime: reportTime + " 00:00:00"
                         };
                         datagrid.datagrid('load');
                     }
                 }
             }

             function selectBattery() {
                 App.dialog.show({
                     css: 'width:826px;height:522px;overflow:visible;',
                     title: '选择电池',
                     href: "${contextPath}/security/hdw/battery/select_battery.htm",
                     windowData: {
                         ok: function (config) {
                             $('#battery_id').val(config.battery.id)
                         }
                     },
                     event: {
                         onClose: function () {
                             if (($('#battery_id').val()).length > 0) {
                                 selectQueryFirst($('#battery_id').val());
                             }
                         },
                         onLoad: function () {
                         }
                     }
                 });
             }
             var batteryIdTemp = ${(batteryId)!''} + "";
             if ($.trim(batteryIdTemp).length > 0) {
                 selectQueryFirst(batteryIdTemp);
             }
             function selectQueryFirst(id) {
                 $("#battery_tree").tree({
                     url: '${contextPath}/security/hdw/battery_report_date/tree.htm?batteryId=' + id,
                     onLoadSuccess: function (data) {
                         eval(data)
                     }
                 });
                 var datagrid = $('#page_table');
                 datagrid.datagrid('options').queryParams = {
                     batteryId: id
                 };
                 datagrid.datagrid('load');
             }
         </script>
    </@app.body>
</@app.html>
